class UserController < ApplicationController
  auto_complete_for :thing,:title
  def index
    
  end

  def view
    @user = User.find_by_login(params[:id])
    @user_lists = User.find(:all,:order=>"created_at desc",:limit=>10)
    @top_things = Thing.find(:all,:order=>"created_at desc",:limit=>10)

    created_times = Thingsuser.find(:all,:order=>"updated_at asc",:conditions=>["MONTH(updated_at)=? and YEAR(updated_at)=? and user_id = ?",Time.now.month,Time.now.year,@user.id])
    array_a = ""
    for array_tmp in created_times

      if array_a.index(array_tmp.updated_at.day.to_s).nil?
        array_a << array_tmp.updated_at.day.to_s + ','
      end
    end
    array_a = array_a[0..array_a.size-2]
    @array_a =<<-eol
     #{array_a}
    eol
     
    options ={:page=>params[:page],:per_page=>5}
    user_id = User.find_by_login(params[:id])
    @things = Thing.paginate_by_sql(["select title,tu.updated_at from(select user_id,thing_id,updated_at from thingsusers where user_id=?)tu  left join things on thing_id = things.id",user_id],options)
  end
  
  def things_day
    @user = User.find_by_login(params[:id])
    year = params[:year]
    month = params[:month]
    created_times = Thingsuser.find(:all,:order=>"updated_at asc",:conditions=>["MONTH(updated_at)=? and YEAR(updated_at)=? and user_id = ?",month,year,@user.id])
    array_a = ""
    for array_tmp in created_times
      if array_a.index(array_tmp.updated_at.day.to_s).nil?
        array_a <<  array_tmp.updated_at.day.to_s + ','
      end
    end
    array_a = array_a[0..array_a.size-2]
    array_a =<<-eol
       #{array_a}
    eol
    render :text=>array_a
  end

end
